/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Models;

import java.sql.*;
import java.util.Vector;

/**
 *
 * @author Venus
 */
public class LoaiMA_Model {

    public Vector LayDSLMA(int langid) {
        Vector v = new Vector();
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "select distinct(MaLMA), MaNN, TenLMA from loaimonan where MaNN = " + langid + " Order by MaLMA desc ";
            rss = stmt.executeQuery(query);
            while (rss.next()) {
                Beans.LoaiMonAn lma = new Beans.LoaiMonAn();
                lma.setMaLMA(rss.getInt(1));
                lma.setMaNN(rss.getInt(2));
                lma.setTenLMA(rss.getString(3));
                v.add(lma);
            }
            stmt.close();
            rss.close();
            conn.close();
        } catch (Exception e) {
            e.getMessage();
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return v;
    }
}
